﻿Imports ccapps.persistent.NetworkRequest
Public Class NetworkRequestViewDelete
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("user") = "" Or Session("user") Is Nothing Then
            ' Response.Redirect("../../login.aspx")
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If
    End Sub

    Protected Sub btnCheckMSISDN_Click(sender As Object, e As EventArgs) Handles btnCheckMSISDN.Click
        MSISDNSearch()
    End Sub

    Private Sub MSISDNSearch()

        Try
            lblErrorMessage.Text = ""
            lblAbone.Text = ""
            lblCoID.Text = ""
            lblCustomerID.Text = ""
            baslik3.Visible = False
            pending.Visible = False
            failed.Visible = False
            chckFailed.Checked = False
            chckPending.Checked = False

            Dim pin_MSISDN As String = TB_MSISDN.Text.Trim()
            Dim dt As DataTable = GetCustomerInfoFromMSISDN(pin_MSISDN)
            If dt.Rows.Count > 0 Then
                For Each dr2 As DataRow In dt.Rows
                    lblAbone.Text = dr2("ccfname").ToString() + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                    lblCustomerID.Text = dr2("CUSTOMER_ID").ToString()
                    lblCoID.Text = dr2("CO_ID").ToString()
                Next

            Else
                lblErrorMessage.Text = "Girmiş Olduğunuz MSSIDN'e Ait Bilgi Yoktur."
            End If
        Catch ex As Exception
            lblErrorMessage.Text = "Girmiş Olduğunuz MSSIDN'e Ait Bilgi Yoktur."
        End Try
    End Sub


    Protected Sub btnCheckCOID_Click(sender As Object, e As EventArgs) Handles btnCheckCOID.Click
        CoidSearch()
    End Sub

    Private Sub CoidSearch()

        Try


            lblErrorMessage.Text = ""
            lblAbone.Text = ""
            lblCoID.Text = ""
            lblCustomerID.Text = ""
            baslik3.Visible = False
            pending.Visible = False
            failed.Visible = False
            chckFailed.Checked = False
            chckPending.Checked = False

      
            Dim pin_coid As Integer = Convert.ToInt32(TB_COID.Text.Trim())
            Dim dt As DataTable = GetCustomerInfoFromCOID(pin_coid)
            If dt.Rows.Count > 0 Then
                For Each dr2 As DataRow In dt.Rows
                    lblAbone.Text = dr2("ccfname").ToString() + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                    lblCustomerID.Text = dr2("CUSTOMER_ID").ToString()
                    lblCoID.Text = dr2("CO_ID").ToString()
                Next
            Else
                lblErrorMessage.Text = "Girmiş Olduğunuz COID'ye Ait Bilgi Yoktur."

            End If
        Catch ex As Exception
            lblErrorMessage.Text = "Girmiş Olduğunuz COID'ye Ait Bilgi Yoktur."
        End Try
    End Sub

    Protected Sub btnAra_Click(sender As Object, e As EventArgs) Handles btnAra.Click
        dgNetworkRequestListFailed.Visible = False
        dgNetworkRequestListPending.Visible = False
        Dim hangisi As Integer


        If chckPending.Checked = True Then
            FillPendingRequest()
            hangisi = 1
            pending.Visible = True


        End If

        If chckFailed.Checked = True Then
            FillFailedRequest()
            hangisi = 2
            failed.Visible = True


        End If
        If chckFailed.Checked = True And chckPending.Checked = True Then
            hangisi = 3
            pending.Visible = True
            failed.Visible = True

        End If

    End Sub

    Private Sub FillPendingRequest()
        dgNetworkRequestListPending.Visible = True
        Dim pin_coid As Integer = Convert.ToInt32(lblCoID.Text)
        Dim pin_customer_id As Integer = Convert.ToInt32(lblCustomerID.Text)
        Dim dt As DataTable = DisplayPendingRequests(pin_customer_id, pin_coid)
        If dt.Rows.Count > 0 Then
            baslik2.Visible = True
            baslik3.Visible = True
            dgNetworkRequestListPending.DataSource = dt
            dgNetworkRequestListPending.DataBind()
        Else
            baslik3.Visible = True
            pending.InnerHtml = "Pending Durumunda Aboneye Ait Network Request Listesi Bulunamamıştır."
        End If
        If chckFailed.Checked = False Then
            failed.Visible = False

        End If


       
    End Sub

    Private Sub FillFailedRequest()
        dgNetworkRequestListFailed.Visible = True
        Dim pin_coid As Integer = Convert.ToInt32(lblCoID.Text)
        Dim pin_customer_id As Integer = Convert.ToInt32(lblCustomerID.Text)
        Dim dt As DataTable = DisplayFailedRequests(pin_customer_id, pin_coid)
        If dt.Rows.Count > 0 Then
            baslik.Visible = True
            baslik3.Visible = True
            dgNetworkRequestListFailed.DataSource = dt
            dgNetworkRequestListFailed.DataBind()
        Else
            baslik3.Visible = True
            failed.InnerHtml = "Failed Durumunda Aboneye Ait Network Request Listesi Bulunamamaıştır."
        End If
        If chckPending.Checked = False Then
            pending.Visible = False
        End If

        
    End Sub

    Protected Sub SendRequest(source As Object, e As DataGridCommandEventArgs) Handles dgNetworkRequestListPending.ItemCommand

        If e.CommandName = "resend" Then
            Dim dt As DataTable = NetworkRequestResend(e.Item.Cells(2).Text)
            FillPendingRequest()

        End If

        If e.CommandName = "delete" Then
            Dim dt As DataTable = NetworkRequestCancel(e.Item.Cells(2).Text)
            FillPendingRequest()
        End If
    End Sub

    Protected Sub SendRequestFailed(source As Object, e As DataGridCommandEventArgs) Handles dgNetworkRequestListFailed.ItemCommand
        If e.CommandName = "resend" Then
            Dim dt As DataTable = NetworkRequestResend(e.Item.Cells(2).Text)
            FillFailedRequest()

        End If

        If e.CommandName = "delete" Then
            Dim dt As DataTable = NetworkRequestCancel(Convert.ToInt32(e.Item.Cells(2).Text))
            FillFailedRequest()
            lblErrorMessage.Text = dt.Rows.Count.ToString




        End If
    End Sub
End Class